<template>
  <common-card
    title="累计销售额"
    :value="salesToday">
    <template>
      <div class="compare-wrapper">
        <div class="compare">
          <span>日同比</span>
          <span class="emphasis">{{ salesGrowthLastDay | pct }}</span>
          <div class="increase"/>
        </div>
        <div class="compare">
          <span>月同比</span>
          <span class="emphasis">{{ salesGrowthLastMonth | pct }}</span>
          <div class="decrease"/>
        </div>
      </div>
    </template>
    <template v-slot:footer>
      <span>昨日销售额 </span>
      <span class="emphasis">{{ salesLastDay | money }}</span>
    </template>
  </common-card>
</template>

<script>
import commonCardMixin from '@/mixins/commonCardMixin'
import commonFillters from '@/mixins/commonFilters'
import { money } from '@/utils'
import { totalSales } from '@/api/axiosHttp'

export default {
  name: 'TotalSales',
  data () {
    return {
      salesGrowthLastDay: 0,
      salesGrowthLastMonth: 0,
      salesLastDay: 0,
      salesToday: 0
    }
  },
  mixins: [commonCardMixin, commonFillters],
  created () {
    totalSales().then(data => {
      const {
        salesGrowthLastDay,
        salesGrowthLastMonth,
        salesLastDay,
        salesToday
      } = data
      this.salesGrowthLastDay = salesGrowthLastDay
      this.salesGrowthLastMonth = salesGrowthLastMonth
      this.salesLastDay = salesLastDay
      this.salesToday = money(salesToday)
    })
  }
}
</script>

<style scoped lang="scss">
.compare-wrapper {
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: center;

  .compare {
    display: flex;
    align-items: center;
    font-size: 12px;
    margin-top: 3px;
    color: #666;
  }
}
</style>
